<script type="text/javascript"><!--//--><![CDATA[//><!--

	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};

	var grid_reload_expire = function(){
		$('#datagrid').datagrid('reload', {'status':'expired'});
	};

	$(document).ready(function() {

		// Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },
				{ field : 'kode_alat', title : 'Kode Alat', width : 120, sortable:true },
				//{ field : 'nama', title : 'Nama', width : 120, sortable:true },
				{ field : 'nama_peralatan', title : 'Nama Peralatan', width : 120, sortable:true },
				{ field : 'nomor_sertifikasi', title : 'Nomor Sertifikasi', width : 120, sortable:true },
				{ field : 'tgl_berlaku_awal', title : 'Tanggal Berlaku Awal', width : 120, sortable:true },
				{ field : 'tgl_berlaku_akhir', title : 'Tanggal Berlaku Akhir', width : 120, sortable:true },
			]]
		});

		// $('#datagrid2').datagrid2({  
		// 	url:gs_path+'/'+controller+'/getdata', 
		// 	queryParams: $('#fm_search').serializeObject(),
		// 	height:340,
		// 	pagination:true,
		// 	columns:[[
		// 		{ field : 'ck', checkbox:true, width: 40, align: 'center' },
		// 		{ field : 'kode_alat', title : 'Kode Alat', width : 120, sortable:true },
		// 		//{ field : 'nama', title : 'Nama', width : 120, sortable:true },
		// 		{ field : 'nama_peralatan', title : 'Nama Peralatan', width : 120, sortable:true },
		// 		{ field : 'nomor_sertifikasi', title : 'Nomor Sertifikasi', width : 120, sortable:true },
		// 		{ field : 'tgl_berlaku_awal', title : 'Tanggal Berlaku Awal', width : 120, sortable:true },
		// 		{ field : 'tgl_berlaku_akhir', title : 'Tanggal Berlaku Akhir', width : 120, sortable:true },
		// 	]]
		// });		
		
		// Setup Form
		$('#form_master').setupForm([			
			{ name: 'kode_alat', type: 'text', size: 'medium', maxlength: 15, noempty:true },
			{ name: 'nama_peralatan', type: 'text', size: 'medium', maxlength: 255, noempty:true },
			{ name: 'nomor_sertifikasi', type: 'text', size: 'medium', maxlength: 255 },
			{ name: 'tgl_berlaku_awal', type: 'date', size: 'medium', maxlength: 255 },
			{ name: 'tgl_berlaku_akhir', type: 'date', size: 'medium', maxlength: 255 },			
			
		]);
		
		
		// Create Dialog
		$('#dialog_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:600,
			height:400,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					$('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ loadPage(gs_path + '/' + controller + '/index'); /*$('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload');*/ }} );

				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#dialog_container').dialog('close');
				}
			}]
		});

		
		
		
		// Set Action Button
		var buttons = [ { label: 'Warning Sertifikasi Peralatan Expired', icon: 'bug', onclick: function() {
							// resetError();
							// $('#dialog_container').dialog('open');
							grid_reload_expire();
					    }}, { label: 'Add', icon: 'add', onclick: function() {
							resetError();
							$.ajax({
								url:gs_path+'/'+controller+'/id_auto',
								type:'POST',
								dataType:'JSON',
								}).done(function(data){
									$('#id_sertifikasi').setval(data['id_sertifikasi_auto']);
									$('#kode_alat').setval(data['kode_alat_auto']);
							});
							$('#dialog_container').dialog('open');
							$('#form_master').data('mode', 'create');
							$('#form_master').parent().parent().parent().prev().find('.panel-title').html('New Sertifikasi Peralatan');
							$('#kode_alat').readonly(true);
							$('#kode_alat, #nama_peralatan, #nomor_sertifikasi, #tgl_berlaku_awal, #tgl_berlaku_akhir').val('');
							$('#kode_alat').setval(kode_alat_auto);
							$('#kode_alat').focus();
						} },
						{ label: 'Edit', icon: 'edit',  onclick: function() {
							var oSel=$('#datagrid').datagrid('getSelected'); 
							if(oSel==null){ alert('Please select row!'); }
							else{ 
								resetError();
								$('#dialog_container').dialog('open'); 
								$('#form_master').data('mode', 'edit');
								$('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Sertifikasi Peralatan');
								$('#kode_alat').readonly();
								jsonToForm(oSel); $('#kode_alat').focus();
							} 
						} },
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['kode_alat']);
							} 
						}}, { label: 'Print PDF', icon: 'print', onclick: function() {
                            window.open(gs_path+'/pro_kontrol_sertifikasi/cetak', 'myWin', 'height=500,width=700,status=yes,toolbar=no,menubar=yes,location=no,scrollbars=yes');
                        }},
						{ label: 'Print to Excel', icon: 'print', onclick: function() {
					    	window.location = gs_path + '/pro_print_excel_new/kontrol_sertifikasi_peralatan';
					    }}];
		setAction(buttons);
		
		
		$('#fm_search').focusFirst();
	});
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>


<div id="dialog_container" style="padding:5px;width:600px;height:380px;">
	<form id="form_master">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
    	<td>
    		<input id="id_sertifikasi" name="id_sertifikasi" type="hidden" />
    	</td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Kode Alat</td>
        <td><input id="kode_alat" /></td>
    </tr>
    <tr>
        <td class="label">Nama Peralatan</td>
        <td><input id="nama_peralatan" /></td>
    </tr> 
	<tr>
        <td class="label">Nomor Sertifikasi</td>
        <td><input id="nomor_sertifikasi" /></td>
    </tr>               
    <tr>
        <td class="label">Tanggal Berlaku Awal</td>
        <td><input id="tgl_berlaku_awal" /></td>
    </tr>
    <tr>
        <td class="label">Tanggal Berlaku Akhir</td>
        <td><input id="tgl_berlaku_akhir" /></td>
    </tr>
    </table>
	</form>
</div>